#!/bin/bash
AppName=teld-1.0
AppPort=8089
PID=""
APP_HOME=`pwd`
query(){
  PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
}
query
echo "PID="$PID
if [ x"$PID" != x"" ]; then
		kill -TERM $PID
		echo $AppPort" 端口已经被占用，正在停用该端口..."
		echo "$AppName (pid:$PID) exiting..."
		while [ x"$PID" != x"" ]
		do
			sleep 1
			query
		done
		echo "$AppName exited."
    echo "git pull"
    git pull
    mvn clean
    mvn package -DskipTests
    cp $APP_HOME/target/$AppName.jar $APP_HOME/$AppName.jar
    nohup java -jar $AppName.jar > /dev/null 2>&1 &
	else
    echo "git pull"
    git pull
    mvn clean
    mvn package -DskipTests
    cp $APP_HOME/target/$AppName.jar $APP_HOME/$AppName.jar
    nohup java -jar $AppName.jar > /dev/null 2>&1 &
	fi

